package com.handpay.nocardpay.baselibrary.pay.unipay.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.pay.unipay.model.HistoryBankCardDelModelImpl;
import com.handpay.nocardpay.baselibrary.pay.unipay.model.HistoryBankCardListModelImpl;
import com.handpay.nocardpay.baselibrary.pay.unipay.model.bean.HistoryBankCardDelBean;
import com.handpay.nocardpay.baselibrary.pay.unipay.model.bean.HistoryBankCardListBean;
import com.handpay.nocardpay.baselibrary.pay.unipay.view.IHistoryCardView;

import java.util.HashMap;

/**
 * Created by lyang on 2017/8/15.
 */

public class HistoryBankCardListPresenter implements IBaseModel.OnRequestFinishedListener<HistoryBankCardListBean> {
    private HistoryBankCardListModelImpl mHistoryBankCardListModelImpl;
    private HistoryBankCardDelModelImpl mHistoryBankCardDelModelImpl;
    private IHistoryCardView mHistoryCardView;

    public HistoryBankCardListPresenter(Context context, IHistoryCardView view) {
        this.mHistoryBankCardListModelImpl = new HistoryBankCardListModelImpl(context);
        this.mHistoryBankCardDelModelImpl = new HistoryBankCardDelModelImpl(context);

        mHistoryCardView = view;
    }


    public void getHistoryBankCardList(HashMap<String, Object> paramers, Class<HistoryBankCardListBean> clzz, boolean isShowLoading) {
        if (mHistoryCardView != null) {
            if (isShowLoading) {
                mHistoryCardView.showProgress();
            }
        }
        mHistoryBankCardListModelImpl.request(paramers, clzz, this);
    }


    public void doDelHistoryBankCardList(HashMap<String, Object> paramers, Class<HistoryBankCardDelBean> clzz, boolean isShowLoading) {
        if (mHistoryCardView != null) {
            if (isShowLoading) {
                mHistoryCardView.showProgress();
            }
        }
        IBaseModel.OnRequestFinishedListener listener = new IBaseModel.OnRequestFinishedListener<HistoryBankCardDelBean>() {

            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                mHistoryCardView.hideProgress();
            }

            @Override
            public void onSuccess(HistoryBankCardDelBean response) {
                mHistoryCardView.hideProgress();
            }
        };


        mHistoryBankCardDelModelImpl.request(paramers, clzz, listener);
    }


    public HistoryBankCardListModelImpl getmHistoryBankCardListModelImpl() {
        return mHistoryBankCardListModelImpl;
    }

    @Override
    public void onError(BaseErrorInfo baseErrorInfo) {
        mHistoryCardView.hideProgress();
    }

    @Override
    public void onSuccess(HistoryBankCardListBean response) {
        mHistoryCardView.hideProgress();
        mHistoryCardView.queryHistorySuccess(response);
    }
}
